package com.ylr.blog.framework.resolver;

import com.ylr.base.common.exception.YlrException;
import com.ylr.base.common.tool.Result;
import com.ylr.blog.framework.feign.client.YbBlogSpaceClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-06-13 16:30:20
 * className: YbBlogSpaceResolver
 * version: 1.0
 * description:
 */
@Component
public class YbBlogSpaceResolver {

    private static final Logger log = LoggerFactory.getLogger(YbBlogSpaceResolver.class);

    @Value("${spring.application.simple-name:ylr}")
    private String applicationSimpleName;

    private final YbBlogSpaceClient ybBlogSpaceClient;

    public YbBlogSpaceResolver(YbBlogSpaceClient ybBlogSpaceClient) {
        this.ybBlogSpaceClient = ybBlogSpaceClient;
    }

    /**
     * 添加用户博客空间操作
     * @param userId 用户主键
     * @param name   空间名称
     */
    public void addBlogSpace(Long userId, String name) {
        Result<Object> result = ybBlogSpaceClient.addBlogSpace(userId, name);
        if (result.isFail()) {
            log.warn("{}模块 => 添加用户博客空间操作失败。message={}", applicationSimpleName, result.getMsg());
            throw new YlrException(result);
        }
    }
}
